package basic.com.liz.learn.thread;

public class Factory
{
    private int num = 0;
    
    private boolean created = false;
    
    public synchronized void create()
    {
        while (created)
        {
            try
            {
                wait();
            }
            catch (InterruptedException e)
            {
                System.out.println(e.getMessage());
            }
        }
        num++;
        System.out.println(Thread.currentThread().getName() + "-生产者-" + num);
        this.created = true;
        notifyAll();
        
    }
    
    public synchronized void consume()
    {
        while (created)
        {
            System.out.println(Thread.currentThread().getName() + "-消费者-" + num);
            this.created = false;
            notifyAll();
        }
        try
        {
            wait();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
        
    }
    
}
